<?php
include('rootlogin.php');
//include('../incsession.php');
session_start();
$level=1;
if($_POST['submit']=="next"){
	$i=1;
	$number=$_POST['OQ'];
	while($i <= $number)
	{	
		if($_POST['Q'.$i]!='' && $_POST['answer'.$i]!='' &&
			$_POST['Q'.$i]!=' ' && $_POST['answer'.$i]!=' '){
			
			
			$Q = str_replace("'", "&#39;", $_POST['Q'.$i]);
			$Q = str_replace('"', '&quot;', $Q);
			$A = str_replace("'", "&#39;", $_POST['answer'.$i]);
			$A = str_replace('"', '&quot;', $A);
			$query = "INSERT INTO open_question (question, answer, topicid, level) 
					VALUES ('".$Q."',
							'".$A."', 
							".$_SESSION['topicid'].", ".$level.")";
			$result = mysql_query($query,$user_con);
		}
		$i++;
	}
	header("location: drag_and_drop1.php");	
}
if(!isset($_POST['OQ'])){
			$OQ=1;
}
else {
			$OQ=$_POST['OQ'];
			$OQ++;
}

?>

<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="framestyle.css" type="text/css" media="screen">
<style type="text/css">

</style>
</head>


<body>

<div id="wrapper">
<div id="title">Online Listening Comprehension Program</div>

<div id="main">
<hr/>
<div id="title2">FOR EASY LEVEL: OPEN QUESTIONS</div>
<hr/>
<br><br>
<form method = POST action="open_question1.php" >
<?php
$i=1;

//echo "jj\"\"jj";
while($i<=$OQ){
	$Q = str_replace("'", "&#39;", $_POST['Q'.$i]);
	$Q = str_replace('"', '&quot;', $Q);
	$A = str_replace("'", "&#39;", $_POST['answer'.$i]);
	$A = str_replace('"', '&quot;', $A);
	echo '<table>';
	echo '<tr><td align="right">Q'.$i.': <td><input class="area long" type="text" name="Q'.$i.'" value="'.$Q.'">
			<tr><td align="right">A'.$i.': <td><input class="area long" type="text" name="answer'.$i.'" value="'.$A.'"></table>';	
	echo "<br>";
	$i++;
}

echo "<input type='hidden' name='OQ' value=".$OQ.">";

?>

<div class="btn_right"><input type="submit" name = "submit" value = "add"></div><br>
<div class="btn_right"><input type="submit" name = "submit" value = "next"></div>
</form>
</div>
</div>
</body>

